import { LoadingBar } from 'quasar'
import InterfaceProxy from 'src/utils/mider'
import { defaultOptions, ResponseData } from '../_options'

/**
 * 工具
 * @namespace iContent
 */

/** @lends iContent# */
const interfaceOpt = {
  create: {
    name: '新增',
    url: 'p/v1/km-api/create',
    method: 'post',
    params: {
      data: Object
    },
    beforeSend () {
      LoadingBar.start()
    },
    successHandler (res: ResponseData) {
      LoadingBar.stop()
      return {
        success: res.code === 0,
        data: res.data,
        msg: res.msg
      }
    }
  },
  update: {
    name: '保存/更新内容',
    url: 'p/v1/km-api/update',
    method: 'post',
    params: {
      data: Object
    }
  },
  findContents: {
    url: 'p/v1/km-api/article',
    method: 'get',
    params: {
      route: String, // detail：artcile全文
      id: String,
      tags: Array,
      keywords: String,
      ids: Array,
      sorts: String
    },
    beforeSend () {
      LoadingBar.start()
    },
    successHandler (res: ResponseData) {
      LoadingBar.stop()
      return {
        success: res.code === 0,
        data: res.data,
        msg: res.msg
      }
    }
  },
  getList: {
    url: '/p/v1/km-api/pm/list',
    method: 'get'
  },
  getMenu: {
    url: '/p/v1/km-api/menu',
    method: 'get',
    params: {
      data: Object
    }
  },
  findAllTags: {
    url: '/p/v1/km-api/tags',
    method: 'get',
    validTime: 60
  }
}

/** @mixes iContent */
const iWoshipm = new InterfaceProxy(interfaceOpt, [defaultOptions])
export default iWoshipm
